package com.etone.smartAudit.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.etone.smartAudit.domain.Admin;
import com.etone.smartAudit.domain.ProjectFileLog;
import com.etone.smartAudit.mapper.ProjectFileLogMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 操作日志 记录文件操作记录 服务实现类
 * </p>
 *
 * @author jiayen
 * @since 2021-05-08
 */
@Service
public class ProjectFileLogService extends ServiceImpl<ProjectFileLogMapper, ProjectFileLog> {


    /***
     * 记录操作日志
     */
    public void saveLog(Admin admin, Integer fileId, String action) {
        ProjectFileLog log = ProjectFileLog.builder()
                .fileId(fileId)
                .action(action)
                .createdBy(admin.getId())
                .createdTime(new Date())
                .createdName(admin.getNickName())
                .updatedTime(new Date())
                .build();
        this.save(log);
    }

    /**
     * 获取项目日志
     *
     * @param fId
     * @return
     */
    public List<ProjectFileLog> getList(Integer fId) {
        LambdaQueryWrapper<ProjectFileLog> query = new LambdaQueryWrapper<>();
        query.eq(ProjectFileLog::getFileId, fId)
                .orderByDesc(ProjectFileLog::getCreatedTime);
        return this.list(query);
    }
}
